<?php
/**
 * Created by PhpStorm.
 * User: andyge
 * Date: 15/11/8
 * Time: 上午8:54
 */

include_once("../libs/login.php");
include_once("../libs/template.php");

$login = new Login();
$login->check_logined();

$template = new Template();
echo $template->header();

class Res
{
    var $file;
    var $size;
    var $md5;
    var $time;
    var $tag;
};

error_log("test err log");

function get_res_list() {
    $res_list = array();
    $dir = opendir("../upload/");
    if(!$dir) {
        return $res_list;
    }

    $file = readdir($dir);
    while($file) {
        error_log("readdir".$file);
        if(is_dir("../upload/".$file)) {
            $file = readdir($dir);
            continue;
        }
        #print("file:".$file);
        error_log("file:".$file);
        $res = new Res();
        $res->file = $file;
        $res->size = filesize("../upload/".$file);
        $res->time = "";
        $res->md5 = md5_file("../upload/".$file);
        $res->tag = "client, server";
        $res_list[count($res_list)] = $res;
        error_log("res:".$res->file);
        $file = readdir($dir);
    }

    return $res_list;
}

#$upload_msg = "";
?>

            <div class="navbar-default sidebar" role="navigation">
                <div class="sidebar-nav navbar-collapse">
                    <ul class="nav" id="side-menu">
                        <li class="sidebar-search">
                            <div class="input-group custom-search-form">
                                <input type="text" class="form-control" placeholder="Search...">
                                <span class="input-group-btn">
                                    <button class="btn btn-default" type="button">
                                        <i class="fa fa-search"></i>
                                    </button>
                                </span>
                            </div>
                            <!-- /input-group -->
                        </li>
                        <li>
                            <a href="index.php"><i class="fa fa-dashboard fa-fw"></i> 首页</a>
                        </li>
                        <li class="active">
                            <a href="#"><i class="fa fa-bar-chart-o fa-fw"></i> 资源<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                <li class="active">
                                    <a href="res_upload.php"> 上传</a>
                                </li>
                                <li>
                                    <a href="#" class="active"> 列表</a>
                                </li>
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                        <li>
                            <a href="#"><i class="fa fa-table fa-fw"></i> 主机</a>
                        </li>
                        <li>
                            <a href="#"><i class="fa fa-edit fa-fw"></i> 任务</a>
                        </li>

                    </ul>
                </div>
                <!-- /.sidebar-collapse -->
            </div>
            <!-- /.navbar-static-side -->
        </nav>

        <!-- Page Content -->
        <div id="page-wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">资源列表</h1>
                    </div>
                    <!-- /.col-lg-12 -->
                </div>
                <!-- /.row -->
                <div class="row">
                    <div class="col-lg-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">

                            </div>
                            <div class="panel-body">
                                <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th>文件</th>
                                            <th>大小</th>
                                            <th>MD5</th>
                                            <th>标签</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                        $res_list = get_res_list();
                                        #error_log($res_list);
                                        foreach($res_list as $res) {
                                            error_log("res xx:".$res->file);
                                            echo "<tr class=\"odd gradeX\">";
                                            echo "<td>" . $res->file . "</td>";
                                            echo "<td>" . $res->size . "</td>";
                                            echo "<td>" . $res->md5 . "</td>";
                                            echo "<td>" . $res->tag . "</td>";
                                            echo "</tr>";
                                        }
                                    ?>

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <!-- /.container-fluid -->

        </div>
<?php
echo $template->footer();
?>